﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ProgramMain.OpticNet
{
    public partial class DocumentDetail : ProgramMain.Framework.BaseModalDetailCtl
    {
        public DocumentDetail()
        {
            InitializeComponent();
        }

        public byte[] content { get; private set; } 
        protected override void BindDataControls()
        {
            this.txtCaption.DataBindings.Add(new Binding("Text", this.dataSource, "Caption"));
            this.txtFileName.DataBindings.Add(new Binding("Text", this.dataSource, "FileName"));
            this.memoDescription.DataBindings.Add(new Binding("Text", this.dataSource, "Description"));
        }

        private void txtFileName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if(e.Button.Tag.ToString() == "open")
            {
                if(openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    txtFileName.Text = openFileDialog1.SafeFileName;
                    using (System.IO.Stream reader = openFileDialog1.OpenFile())
                    {
                        content = new byte[reader.Length];
                        reader.Read(content, 0, content.Length);
                    }
                    CurrentRowView.Row["Size"] = content.Length;

                }
            }
        }

    }
}
